package com.ogilvy.cms.dao.impl;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.apache.struts2.ServletActionContext;
import org.hibernate.Query;
import org.springframework.stereotype.Repository;

import com.ogilvy.cms.bean.CmsTemplate;
import com.ogilvy.cms.dao.CmsTemplateDao;
import com.ogilvy.frame.hibernate.BaseDaoImpl;
@Repository
public class CmsTemplateDaoImpl extends BaseDaoImpl<CmsTemplate> implements CmsTemplateDao{
	public List<CmsTemplate> getListByScreen(Map<String,String> screenMap) {
		StringBuffer hql=new StringBuffer();
		hql.append("from com.ogilvy.cms.bean.CmsTemplate ct where ");
		 hql.append("ct.cmtName like '%"+screenMap.get("cmtName")+"%'");
		// 建立查询语句
		Query query = getSession().createQuery(hql.toString());
		List<CmsTemplate>  list = query.list();
		if (list == null) {
			list = new ArrayList<CmsTemplate>();
		}
		return list;
	}

	public List<CmsTemplate> SelectTempByName(Map<String,String> screenMap) {
		StringBuffer hql=new StringBuffer();
		hql.append("from com.ogilvy.cms.bean.CmsTemplate ct where ");
		 hql.append("ct.cmtName '%"+screenMap.get("cmtName")+"%'");
		 Query query = getSession().createQuery(hql.toString());
			List<CmsTemplate>  list = query.list();
			if (list == null) {
				list = new ArrayList<CmsTemplate>();
			}
			return  list;
	}

	public Boolean isHaveName(String cmtName) {
		StringBuffer hql=new StringBuffer();
		hql.append("from com.ogilvy.cms.bean.CmsTemplate ct where ");
		hql.append(" ct.cmtName = '"+cmtName+"'");
		Query query = getSession().createQuery(hql.toString());
		List<CmsTemplate>  list = query.list();
		if (list == null || list.size()==0) {
			return false;
		}else
		{
			return true;
		}
	}
}
